<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2014 X.commerce, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Create account form template
 *
 * @see app/design/frontend/base/default/template/customer/form/register.phtml
 */
/** @var $this Mage_Customer_Block_Form_Register */
?>

<form action="<?php echo $this->getUrl('complex/account/modifyedcreatePost') ?>" method="post" id="form-validate">
    <div class="register-two">

        <div class="buttons-set buttons-registers">
            <div class="address-bor clearfix">
                <div class="address-form clearfix">
                <div class="input-box input-address">
                    <?php
                        $provinces = array();
                        $collection = Mage::getModel('directory/region')->getCollection()->addFieldToFilter('country_id', array('eq'=>'CN'));
                        $provinces[] = array('value'=>'','label'=>'-请选择-');
                        foreach($collection as $region)
                        {
                            $provinces[] = array('value'=>$region->getId(),'label'=>$region->getName());
                        }
                    ?>
                    <select id="province_id" name="region_id">
                        <?php foreach($provinces as $prov):?><option value="<?php echo $prov['value']?>"><?php echo $prov['label']?></option><?php endforeach;?>
                    </select>
                    <i class="fa fa-angle-right menu-all-block-iRight"></i>
                </div>

                <div class="input-box input-address">
                    <?php
                        $citys[] = array('value'=>'','label'=>'-请选择-');
                    ?>
                    <select id="city_id" name="city_id">
                        <?php foreach($citys as $city):?><option value="<?php echo $city['value']?>"><?php echo $city['label'];?></option><?php endforeach;?>
                    </select>
                    <i class="fa fa-angle-right menu-all-block-iRight"></i>
                </div>

                <div class="input-box input-address">
                    <select id="website_id" name="website_id" class="required-entry">
                        <option>-请选择-</option>
                    </select>
                    <i class="fa fa-angle-right menu-all-block-iRight"></i>
                    <input type="hidden" name="city" id="city" value=""/>
                </div>

                <div class="input-box input-address">
                    <input type="text" name="street" placeholder="输入详细收货地址"/>
                </div>

                <div class="input-box input-address">
                    <input type="text" name="firstname" placeholder="输入收货人姓名"/>
                </div>

                <div class="input-box input-address">
                    <input type="text" name="telephone" placeholder="输入收货人电话"/>
                </div>

                <div class="input-box input-address">
                    <input type="text" name="postcode" placeholder="邮政编码"/>
                </div>
                </div>
            </div>
        </div>               
    </div>
    <button id="good-btn" type="submit" title="<?php echo $this->__('Submit') ?>" class="button"><span><span><?php echo $this->__('完成注册') ?></span></span>
        </button> 
</form>
<script type="text/javascript">
    //<![CDATA[
    var dataForm = new VarienForm('form-validate', true);
    /*addressInit('cmbProvince', 'cmbCity', 'cmbArea', '湖北', '襄阳市', '襄城区');

    
    new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
    */
    //]]>
    jQuery(document).ready(function(){
        var $ = jQuery;
        if($('#province_id').val()=='') 
        {
            $('#city_id').attr('disabled',true);
            $('#website_id').attr('disabled',true);
        }
        $('.input-address').click(function(){
        $(this).find("select").css("background","url('<?php echo $this->getSkinUrl('images/i_dropdown.png'); ?>') no-repeat scroll right center #fff");
        $(this).find(".fa").css("display","none");
        });
        $('#province_id').change(function(){
            
            $.getJSON('<?php echo $this->getUrl('zgb/ajax/citys')?>?id='+$(this).val(), function(data){
                $('#city_id').empty();
                $('#website_id').empty();
                var option = $('<option>').val('').text('-请选择-');
                $('#website_id').append(option);
                for(var i=0; i<data.length;i++)
                {
                    var option = $('<option>').val(data[i].value).text(data[i].label);
                    $('#city_id').append(option);
                }
                $('#city_id').attr('disabled',false);
                $('#website_id').attr('disabled',true);
                $('#city_id').find('option:first').attr('selected',true);
            });
        });
        $("#city_id").change(function(){
            $('#website_id').attr('disabled',true);
            $.getJSON('<?php echo $this->getUrl('zgb/ajax/websites')?>?id='+$(this).val(), function(data){
                $('#website_id').empty();
                for(var i=0; i<data.length;i++)
                {
                    var option = $('<option>').val(data[i].value).text(data[i].label);
                    $('#website_id').append(option);
                }
                $('#website_id').attr('disabled',false);
                $('#website_id').find('option:first').attr('selected',true);
            });
        });


        $('#website_id').change(function(){
            var val = $("#website_id").val();
            if(val)
            {
                var city = $("#city_id option:selected").text()+' '+$("#website_id option:selected").text();
                $("#city").val(city);
            }
        });
    });
</script>
